<script>
    // ...  扩展运算符 spread

    // 语法：
    // ...(伪)数组
    // ...(伪)对象

    // // 作用：展开数组和对象
    // let arr=[1,2,3,4,5]

    // console.log(...arr);  //1 2 3 4 5  把数组展开了
    // console.log(1,2,3,4,5);


    // // ...[1,2,3,4,5] =  1,2,3,4,5   展开数组


    // // ----------------------------

    // let obj={
    //     name:"zs",
    //     age:18,
    //     sex:"女"
    // }

    // // ...{name:"zs",age:18,sex:"女" }  =  name:"zs",age:18,sex:"女"  展开对象

    // 没有办法打印
    // console.log(...obj);
    // console.log( name:"zs",age:18,sex:"女" );



    // 应用：
    // 将数组当作实参进行传递、浅拷贝、数组合并、对象合并、伪数组转真正的数组


    // 数组合并
    let arr1 = [1, 2, 3, 4, 5]
    let arr2 = [6, 7, 8, 9]

    let newArr = [...arr1, ...arr2]
    console.log(newArr);//(9) [1, 2, 3, 4, 5, 6, 7, 8, 9]

    // 解析：
    // ...arr1 = 1,2,3,4,5
    // ...arr2 =  6,7,8,9
    // [...arr1 ,  ...arr2] =[ 1,2,3,4,5,6,7,8,9   ]



    // 合并对象
    let obj1 = {
        name: "zs",
        sex: "女"
    }
    let obj2 = {
        age: 18,
        eat: "苹果"
    }

    let newObj = {
        ...obj1,
        ...obj2
    }
    console.log(newObj);//{name: 'zs', sex: '女', age: 18, eat: '苹果'}

    // 解析：
    // ...obj1  =   name:"zs",sex:"女"
    // ...obj2  =   age:18, eat:"苹果"
    // { ...obj1, ...obj2 }  =  { name:"zs",sex:"女",age:18, eat:"苹果" }





    // 伪数组转真正的数组
    console.log("hello");
    console.log([..."hello"]);//(5) ['h', 'e', 'l', 'l', 'o']



    // 浅拷贝
    // console.log([...["a","b","c"]]);

    // let a=["a","b","c"]
    // let b=a //浅拷贝

    // b.push("d")

    // console.log(a,b);


    // let a=["a","b","c"]
    // let b=[...a]

    // b.push("d")

    // console.log(a,b);//['a', 'b', 'c'] (4) ['a', 'b', 'c', 'd']



    
    let a=["a","b","c",[1,2]]
    let b=[...a]

    b.push("d")
    b[3].push(3)

    console.log(a,b);
    //['a', 'b', 'c'] (4) ['a', 'b', 'c', 'd']
    // ['a', 'b', 'c', Array(3)] (5) ['a', 'b', 'c', Array(3), 'd']






    // 将数组当作实参进行传递
    function fun(x,y,z){
        console.log(x,y,z);
    }

    let c=["xxx","yyy","zzz"]

    fun(c[0],c[1],c[2])

    // ...c  =  "xxx","yyy","zzz"
    
    fun(...c)  







</script>